/*This is a test for figuring out 
 * the differences between an array name and a pointer */
#include <stdio.h>
void single_dim(int a[], int n){
	printf("%d\n",a[n-1]);
	printf("sizeof=%lu\n",sizeof(a));
}

/* "int (*a)[3]" is equals to "int[][3]" ,not the "**a"
 * the "int[][3]" is a type which the 2nd dimmension length is 3.
 * So the compiler knows "a[2][2]" is the number in the 3rd column of the 3rd row.
 * While , if it is "int **a", the runtime doesn't know how to parse the address,
 * Try to think about the [jugged array] then you'll understand this more quickly.
 * That's why it will throw a segment fault.
 * */
void multi_dim(int a[][3], int r, int c){
	printf("%d\n",a[r-1][c-1]);
	printf("sizeof=%lu\n",sizeof(a));
	printf("the address is %p\n",&a[r][c]);
	printf("the address is %p\n",a);
}

int main(void){
	int array[5] = {1,2,3,4,5};
	int * p  = array;
	int marray[3][3] = { {1,2,3}, {4,5,6}, {7,8,9} };
	int ** q = marray;
	puts("Transfer an array:");
	single_dim(array,4);
	puts("Transfer an pointer:");
	single_dim(p,4);
	puts("Transfer an array:");
	multi_dim(marray,2,2);
	int i,j;
	for (i = 0; i < 3; ++i)
		for (j = 0; j < 3; ++j) {
			printf(" ADDR:%p", &marray[i][j]);
		}
}
